/**
 * Copyright: Copyright (c)2011
 * Company: 易宝支付(YeePay)
 */
package com.xianda.spring.base.factory;

import com.xianda.spring.base.BaseDirectService;
import com.xianda.spring.base.exception.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author：shaocong.chen
 * @date：2015年10月19日 上午9:48:32
 * @since：1.0-SNAPSHOT
 */
@Service
public class DefaultBaseDirectServiceFactory implements BaseDirectServiceFactory {


	private Map<String, BaseDirectService> directServiceMap = new LinkedHashMap<String, BaseDirectService>();

	@Autowired
	public void setDirectServiceList(List<BaseDirectService> directServiceList) {
		directServiceMap.clear();
		for (BaseDirectService service : directServiceList) {
			directServiceMap.put(service.getName(), service);
		}
	}

	/**
	 * 获取托管账户商户接口服务
	 */
	@Override
	public BaseDirectService getBaseDirectService(String serviceName) {
		if (directServiceMap.containsKey(serviceName)) {
			return directServiceMap.get(serviceName);
		}

//		throw  AppModuleException.SYSTEM_ERROR.create("该服务不存在");
		throw new BaseException("该服务不存在");
	}

}